package com.my.ddd_sample_collections.association_object.domain;

import org.junit.jupiter.api.Test;

import java.util.ArrayList;
import java.util.List;

import static org.junit.jupiter.api.Assertions.assertEquals;

/**
 * 只对domain层业务逻辑进行测试，不依赖任何基础设施（甚至不依赖仓储）
 * （推荐使用该方式）
 */
public class UserTest_domain_object_only {

    @Test
    void test_getTotalSubscriptionFee() {
        //given
        User user = createUser();

        //when
        double fee = user.getTotalSubscriptionFee();

        //then
        assertEquals(15, fee);
    }

    private static User createUser() {
        User user = new User();
        user.setMySubscriptions(createMySubscriptions());
        return user;
    }

    private static MySubscriptions createMySubscriptions() {
        List<Subscription> list = new ArrayList<>();
        list.add(new Subscription(1));
        list.add(new Subscription(2));
        list.add(new Subscription(3));
        list.add(new Subscription(4));
        list.add(new Subscription(5));
        return new MySubscriptionsNormal(list);
    }
}